package com

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object BroadCast {
  def main(args: Array[String]): Unit = {
    val conf=new SparkConf().setMaster("local").setAppName("broadcast_test")
    val sc=new SparkContext(conf);
    val rdd:RDD[String]=sc.parallelize(Array("zhangsan","lisi","wangwu","zhaoliu"))
    val list=List("zhangsan","lisi")
    val broadlist:Broadcast[List[String]] = sc.broadcast(list)
    rdd.filter(s=>{
      val data:List[String] = broadlist.value;
      !data.contains(s)
    }).foreach(println)

    sc.stop()
  }
}
